// import thunk from "redux-thunk";
// import { createStore } from "redux";
// import promise from "redux-promise";
import logger from "./../source/middleware/logger/index";
import promise from "./../source/middleware/redux-promise/index";
import thunk from "./../source/middleware/redux-thunk/index";
import { applyMiddleware, createStore } from "./../source/redux/index";
import reducer from "./reducers/index";
//生成store对象
function logger2({ getState, dispatch }) {
  return function (next) {
    //next是为了调用原生的dispatch方法
    return function (action) {
      console.log(`老状态2:${JSON.stringify(getState())}`);
      next(action);
      console.log(`新状态2:${JSON.stringify(getState())}`);
    };
  };
}
const store = createStore(
  reducer,
  applyMiddleware(logger, logger2, thunk, promise)
);

// const store = applyMiddleware(logger, logger2)(createStore)(reducer); //内部会第一次调用reducer函数，得到初始state

export default store;
